package com.vitabuybuy.tv.ui.mine.dredge.viewmodel

import androidx.lifecycle.MutableLiveData
import com.library.common.base.BaseViewModel
import com.library.common.base.MessageModel
import com.library.common.ext.rxHttpRequest
import com.library.common.net.error.msg
import com.library.common.toast.XToast
import com.vitabuybuy.tv.dto.DredgeStroeInfoDto
import com.vitabuybuy.tv.network.AddressRepository
import com.vitabuybuy.tv.network.AuthRepository
import com.vitabuybuy.tv.network.CoinRepository
import com.vitabuybuy.tv.network.DredgeStoreRepository

class DredgeStoreViewModel : BaseViewModel() {

    val storeInfo = MutableLiveData<DredgeStroeInfoDto>()
    fun getDredgeStoreInfo() {
        rxHttpRequest {
            onRequest = {
                storeInfo.value = DredgeStoreRepository.getStoreInfomation().await()
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    fun getAllStroeCate() {
        rxHttpRequest {
            onRequest = {
                val it = DredgeStoreRepository.getAllStroeCate().await()
                defUI.msgEvent.postValue(MessageModel(4, obj = it))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    fun dredgeStore(params: HashMap<String, Any>) {
        rxHttpRequest {
            onRequest = {
               DredgeStoreRepository.dredgeStore(params).await()
                defUI.msgEvent.postValue(MessageModel(3))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    fun uploadImage(path: String) {
        rxHttpRequest {
            onRequest = {
                val it = AuthRepository.upLoadImage(path).await()
                defUI.msgEvent.postValue(MessageModel(1, obj = it))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }

    fun getRegionList(regionId: Int?) {
        rxHttpRequest {
            onRequest = {
                val it =  AddressRepository.getRegionList(regionId) .await()
                defUI.msgEvent.postValue(MessageModel(2, obj = it))
            }
            onError = {
                XToast.normal(it.msg)
            }
            isShowDialogRequest = true
        }
    }
}
